package view;

import handler.LoginHandler2;

import javax.swing.*;
import java.awt.*;

public class Main extends JFrame {

    JLabel nameLabel = new JLabel("系统选择", JLabel.CENTER);
    SpringLayout springLayout = new SpringLayout();
    JPanel centerPanel = new JPanel(springLayout);
    JButton stuBtn = new JButton("教师端");
    JButton teacherBtn = new JButton("学生端");
    LoginHandler2 loginHandler2;

    public Main() {
        super("学生成绩发布系统");
        loginHandler2 = new LoginHandler2(this);
        //内容面板
        Container contentPane = getContentPane();

        nameLabel.setFont(new Font("华文行楷", Font.PLAIN, 40));
        Font centerFont = new Font("楷体", Font.PLAIN, 20);
        nameLabel.setPreferredSize(new Dimension(0, 80));

//        usernameLabel.setFont(centerFont);
//        userTxt.setPreferredSize(new Dimension(200,30));
//        pwdLabel.setFont(centerFont);
//        pwdField.setPreferredSize(new Dimension(200,30));
        stuBtn.setFont(centerFont);
        teacherBtn.setFont(centerFont);
        //加入面板
//        centerPanel.add(usernameLabel);
//        centerPanel.add(userTxt);
//        centerPanel.add(pwdLabel);
//        centerPanel.add(pwdField);
        //stuBtn.setBounds(50,50,55,55);
        centerPanel.add(stuBtn);
        centerPanel.add(teacherBtn);
        //点击按钮监听
        stuBtn.addActionListener(loginHandler2);
        teacherBtn.addActionListener(loginHandler2);
        //回车登录
        //stuBtn.addKeyListener(loginHandler);
       // teacherBtn.setVisible(false);
        //布局

//        int width = Toolkit.getDefaultToolkit().getScreenSize().width;
//        int height = Toolkit.getDefaultToolkit().getScreenSize().height;
//        int windowsWidth = 600;
//        int windowsHeight = 400;
//        //布局usernameLabel
//        Spring childWidth = Spring.sum(Spring.sum(Spring.width(nameLabel),Spring.width(nameLabel)), Spring.constant(20));
//        int offsetx = childWidth.getValue()/2;
////
//        springLayout.putConstraint(SpringLayout.WEST,usernameLabel,-offsetx,SpringLayout.HORIZONTAL_CENTER,centerPanel);
//        springLayout.putConstraint(SpringLayout.NORTH,usernameLabel,20,springLayout.NORTH,centerPanel);
//
//        //usertxt
//        springLayout.putConstraint(SpringLayout.WEST,userTxt,20,SpringLayout.EAST,usernameLabel);
//        springLayout.putConstraint(SpringLayout.NORTH,userTxt,0,SpringLayout.NORTH,usernameLabel);
//
//        //pwdlabel
//        springLayout.putConstraint(SpringLayout.EAST,pwdLabel,0,SpringLayout.EAST,usernameLabel);
//        springLayout.putConstraint(SpringLayout.NORTH,pwdLabel,20,SpringLayout.SOUTH,usernameLabel);
//
//        //pwdFiled
//        springLayout.putConstraint(SpringLayout.WEST,pwdField,20,SpringLayout.EAST,pwdLabel);
//        springLayout.putConstraint(SpringLayout.NORTH,pwdField,0,SpringLayout.NORTH,pwdLabel);
//
//        //loginbtn
//        springLayout.putConstraint(SpringLayout.WEST,loginBtn,50,SpringLayout.WEST,pwdLabel);
//        springLayout.putConstraint(SpringLayout.NORTH,loginBtn,20,SpringLayout.SOUTH,pwdLabel);

        //





        springLayout.putConstraint(SpringLayout.NORTH, nameLabel, 100, SpringLayout.EAST, stuBtn);
        springLayout.putConstraint(SpringLayout.NORTH, teacherBtn, 100, SpringLayout.NORTH, stuBtn);
//        springLayout.putConstraint(SpringLayout.WEST, nameLabel,20,SpringLayout.EAST,teacherBtn);
//        springLayout.putConstraint(SpringLayout.NORTH, nameLabel,80,SpringLayout.SOUTH, stuBtn);
//        stuBtn.setBounds((width-windowsWidth)/2,(height-windowsHeight)/2,windowsWidth,windowsHeight);
//        teacherBtn.setBounds((width-windowsWidth)/2,(height-windowsHeight)/2,windowsWidth,windowsHeight);


        //窗口属性
        contentPane.add(nameLabel, BorderLayout.NORTH);
        contentPane.add(centerPanel, BorderLayout.CENTER);
        setSize(600, 400);
        setDefaultCloseOperation(DISPOSE_ON_CLOSE);
        setLocationRelativeTo(null);
        setVisible(true);
    }

    public static void main(String[] args) {
        new Main();
    }
}
